//
//  ZBBPlayHistory.m
//  沙哈拉FM
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 S1mpl3. All rights reserved.
//

#import "ZBBPlayHistory.h"
static ZBBPlayHistory *playHistory;
@implementation ZBBPlayHistory

+(ZBBPlayHistory *)shareInstance
{
  static  dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
      playHistory = [[ZBBPlayHistory alloc]init];
        playHistory.playHistoryArray = [NSMutableArray array];
        
    });
    return playHistory;
    
}
-(void)WriteToFile:(NSString *)path
{
    NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    //2.找到document文件夹
    NSString *documents = [array lastObject];
    //3.拼接要存放数组的文件路径
    NSString *documentPath = [documents stringByAppendingPathComponent:path];
    NSArray *tempArray = [NSArray arrayWithArray:playHistory.playHistoryArray];
       [tempArray writeToFile:documentPath atomically:YES];
   }
-(NSMutableArray *)takeHistoryArrayFromFile:(NSString *)path
{
    
    NSString *documents = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
    NSString *documnetPath = [documents stringByAppendingPathComponent:path];
    NSArray *resultArray = [NSArray arrayWithContentsOfFile:documnetPath];
  
     playHistory.playHistoryArray = [NSMutableArray arrayWithArray:resultArray];
    
    return  playHistory.playHistoryArray;
}
-(void)addDictionary:(NSDictionary *)dictionary
{
    if (playHistory.playHistoryArray.count != 0) {
        if (![playHistory.playHistoryArray containsObject:dictionary]) {
            
            [playHistory.playHistoryArray addObject:dictionary];
        }
      }
    else
    {
    [playHistory.playHistoryArray addObject:dictionary];
    }
    
    
}
@end
